package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.FacRelation;
import com.tsingtree.modular.mapper.FacRelationMapper;
import com.tsingtree.modular.model.params.FacRelationParam;
import com.tsingtree.modular.model.result.FacRelationResult;
import  com.tsingtree.modular.service.FacRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;


/**
 * <p>
 * 角色和菜单关联表 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2023-08-31
 */
@Service
public class FacRelationServiceImpl extends ServiceImpl<FacRelationMapper, FacRelation> implements FacRelationService {

    @Override
    public void add(FacRelationParam param){
        FacRelation entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FacRelationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FacRelationParam param){
        FacRelation oldEntity = getOldEntity(param);
        FacRelation newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FacRelationResult findBySpec(FacRelationParam param){
        return null;
    }

    @Override
    public List<FacRelationResult> findListBySpec(FacRelationParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FacRelationParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FacRelationParam param){
        return param.getRelationId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FacRelation getOldEntity(FacRelationParam param) {
        return this.getById(getKey(param));
    }

    private FacRelation getEntity(FacRelationParam param) {
        FacRelation entity = new FacRelation();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
